package com.xdcplus.web.controller.wip;


import com.xdcplus.exceptions.domain.ResponseVO;
import com.xdcplus.mom.controller.AbstractController;
import com.xdcplus.pager.vo.PageVO;
import com.xdcplus.web.common.pojo.dto.wip.WipMarkingDTO;
import com.xdcplus.web.common.pojo.dto.wip.WipMarkingFilterDTO;
import com.xdcplus.web.common.pojo.vo.wip.WipMarkingRecordVO;
import com.xdcplus.web.common.pojo.vo.wip.WipMarkingReportVO;
import com.xdcplus.web.common.pojo.vo.wip.WipMarkingVO;
import com.xdcplus.web.service.wip.WipMarkingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 打标管理表(WipMarking)表服务控制层
 *
 * @author Devin.sang
 * @since 2023-05-15 22:05:44
 */
@Api(tags = "打标管理表(WipMarking)")
@Slf4j
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("wipMarking")
public class WipMarkingController extends AbstractController {

    @Autowired
    private WipMarkingService wipMarkingService;

    @ApiOperation("新增打标管理表")
    @PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO saveWipMarking(@RequestBody @Validated WipMarkingDTO wipMarkingDTO) {

        log.info("saveWipMarking {}", wipMarkingDTO.toString());

        wipMarkingService.saveWipMarking(wipMarkingDTO);

        return ResponseVO.success();
    }

    @ApiOperation("打标管理结批")
    @PostMapping(value = "/closeBatch", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO closeBatch(@RequestParam("markingId")
                                 @NotNull(message = "ID参数不能为空") Long markingId) {

        log.info("closeBatch {}", markingId);
        wipMarkingService.closeBatchForMarking(markingId);
        return ResponseVO.success();

    }

    @ApiOperation("查询打标结批报告")
    @GetMapping(value = "/queryMarkingReport/{wipMarkingId}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "wipMarkingId", dataTypeClass = Long.class, value = "打标管理表ID", required = true),
    })
    public ResponseVO<Object> queryMarkingReport(@PathVariable("wipMarkingId")
                                            @NotNull(message = "打标管理表ID不能为空") Long wipMarkingId) {
        log.info("wipMarkingId {}", wipMarkingId);
        return ResponseVO.success(wipMarkingService.queryMarkingReport(wipMarkingId));
    }

    @ApiOperation("修改打标管理表")
    @PutMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO updateWipMarking(@RequestBody WipMarkingDTO wipMarkingDTO) {

        log.info("updateWipMarking {}", wipMarkingDTO.toString());

        wipMarkingDTO.setUpdatedUser(getAccount());
        wipMarkingService.updateWipMarking(wipMarkingDTO);

        return ResponseVO.success();
    }

    @ApiOperation("删除打标管理表")
    @DeleteMapping(value = "/{wipMarkingId}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "wipMarkingId", dataTypeClass = Long.class, value = "打标管理表ID", required = true),
    })
    public ResponseVO deleteWipMarkingLogical(@PathVariable("wipMarkingId")
                                              @NotNull(message = "打标管理表ID不能为空") Long wipMarkingId) {

        log.info("deleteWipMarkingLogical {}", wipMarkingId);

        wipMarkingService.deleteWipMarkingLogical(wipMarkingId);

        return ResponseVO.success();
    }

    @ApiOperation("批量删除打标管理表")
    @DeleteMapping(value = "/deleteByIds/{wipMarkingIds}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "wipMarkingId", dataTypeClass = Long.class, value = "打标管理表ID", required = true),
    })
    public ResponseVO deleteWipMarkingLogical(@PathVariable("wipMarkingIds")
                                              @NotNull(message = "打标管理表ID不能为空") String wipMarkingIds) {

        log.info("deleteWipMarkingByIds {}", wipMarkingIds);

        wipMarkingService.deleteWipMarkingByIds(wipMarkingIds);

        return ResponseVO.success();
    }

    @ApiOperation("查询打标管理表")
    @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<PageVO<WipMarkingVO>> findWipMarking(WipMarkingFilterDTO wipMarkingFilterDTO) {
        log.info("findWipMarking {}", wipMarkingFilterDTO);
        return ResponseVO.success(wipMarkingService.queryWipMarking(wipMarkingFilterDTO));
    }

    @ApiOperation("查询打标记录详情（流转记录）")
    @GetMapping(value = "/flow/{markingId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<List<WipMarkingRecordVO>> wipMarkingFlow(@PathVariable("markingId")
                                                                   @NotNull(message = "打标ID不能为空") Long wipMarkingId) {
        log.info("findWipMarking {}", wipMarkingId);
        return ResponseVO.success(wipMarkingService.queryWipMarkingFlow(wipMarkingId));
    }

    @ApiOperation("打标管理表结批报告")
    @GetMapping(value = "/report/{wipMarkingId}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "wipMarkingId", dataTypeClass = Long.class, value = "打标管理表ID", required = true),
    })
    public ResponseVO<Object> markingReport(@PathVariable("wipMarkingId")
                                                        @NotNull(message = "打标管理表ID不能为空") Long wipMarkingId) {
        log.info("wipMarkingId {}", wipMarkingId);
        return ResponseVO.success(wipMarkingService.markingReport(wipMarkingId));
    }

}
